<%@page import="java.util.Stack"%>
<div id="header"><jsp:include page="header.jsp"/></div>
<br/>
<%@page import="java.util.Iterator"%>
<%@page import="java.text.SimpleDateFormat"%>
<%@page import="Servlet.dataBaseController"%>
<%@page import="java.util.Vector"%>
<%@page import="java.sql.*"%>
<%@page import="com.mysql.jdbc.Connection"%>
<div id="main-content" style="margin: 0 auto">
        <!--[if IE]><script language="javascript" type="text/javascript" src="../excanvas.pack.js"></script><![endif]-->
        <script type='text/javascript' src='http://ajax.googleapis.com/ajax/libs/jquery/1.4/jquery.min.js'></script>
        <script language="javascript" type="text/javascript" src="js/jquery.flot.js"></script>


        <%
            Connection connection = null;
            Statement st = null;
            ResultSet rs = null;
            String strQuery = null;
            Stack pi = new Stack();
            Stack di = new Stack();
            try {
                connection = dataBaseController.getConnection();
            } catch (Exception e) {
                System.out.println("Error:");
            }

            int c = 0;
            try {
                st = connection.createStatement();
                strQuery = "Select S.PricePerShare, S.Date FROM `brchung`.`stockhistory` S WHERE S.stockid = '" + request.getParameter("symbol") + "' ORDER by S.Date ";
                rs = st.executeQuery(strQuery);
                while (rs.next()) {
                    String price = rs.getString("PricePerShare");
                    Date d = rs.getDate("Date");
                    float p = Float.valueOf(price.trim()).floatValue();

                    if(!di.contains(d.getDate())){
                    pi.push(p);
                    di.push(d.getDate());
                    c++;}
                    

                }
            } catch (Exception e) {
            }
            

            
        %>

<br/><br/><br/><br/><br/><br/>
        <h2><%=request.getParameter("symbol")%> History</h2>
        <div id="placeholder" style="width:600px;height:300px"></div>
        <script language="javascript" type="text/javascript">
 
            var $j = jQuery.noConflict();
 
            $j(function () {
 
                var dataArray = [];
              
              <%if(c==1)
                {%>dataArray.push([<%=di.pop()%>,<%=pi.pop()%>]);<%}
                         else{%>
              dataArray.push([<%=di.pop()%>,<%=pi.pop()%>]);
              dataArray.push([<%=di.pop()%>,<%=pi.pop()%>]);
              dataArray.push([<%=di.pop()%>,<%=pi.pop()%>]);
              dataArray.push([<%=di.pop()%>,<%=pi.pop()%>]);
              dataArray.push([<%=di.pop()%>,<%=pi.pop()%>]);
              dataArray.push([<%=di.pop()%>,<%=pi.pop()%>]);
              dataArray.push([<%=di.pop()%>,<%=pi.pop()%>]);
              <%}%>
              

 
                var data = [
                    {
                        label: "Last 7 days",
                        data: dataArray
                    }
                ];
 
                var options = {
                    legend: {
                        show: true,
                        margin: 10,
                        backgroundOpacity: 0.5
                    },
                    points: {
                        show: true,
                        radius: 3
                    },
                    lines: {
                        show: true
                    },
                    grid: {
                        borderWidth:0
                    },
                      xaxis: {

    tickDecimals: 0
  },
                    yaxis: {
                        tickDecimals: 0
                    }
                };
 
                var plotarea = $j("#placeholder");
 
                $j.plot( plotarea , data, options );
            });
        </script>
        </div>
    <div id="footer" align="center">
        <jsp:include page="footer.jsp"/>
    </div>
